package com.imooc.coupon.advice;

import com.imooc.coupon.exception.CouponException;
import com.imooc.coupon.support.vo.CommonResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * 全局异常处理类
 * Created By TINY
 * Create Time 2020/2/9 - 13:38
 **/
@RestControllerAdvice
public class GlobalExceptionAdvice {

    @ExceptionHandler(value = CouponException.class)
    public CommonResponse<String> handleCouponException(
            HttpServletRequest request, CouponException ex
    ) {
        CommonResponse<String> response = new CommonResponse<>(
                -1, "error: business exception!"
        );
        response.setData(ex.getMessage());

        return response;
    }
}
